package com.jqq.map_;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * @author 姬倩倩
 * @version 1.0
 */
@SuppressWarnings({"all"})
public class MapExercise {
    public static void main(String[] args) {
        Map map = new HashMap();
        Employee jack = new Employee("jack", 18000, 1001);
        Employee smith = new Employee("smith", 19000, 1002);
        Employee mary = new Employee("mary", 20000, 1003);
        map.put(jack.getId(),jack);
        map.put(smith.getId(),smith);
        map.put(mary.getId(),mary);

        //1
        System.out.println("----第1种遍历方式----");
        Set entryset = map.entrySet();
        for (Object obj :entryset) {
            Map.Entry m = (Map.Entry) obj;
            Object value = m.getValue();
            Employee e = (Employee)value;

            if(e.getSal() > 18000){
                System.out.println(e);
            }
        }
        //2
        System.out.println("----第2种遍历方式----");
        Iterator iterator = entryset.iterator();
        while (iterator.hasNext()) {
            Object obj =  iterator.next();
            Map.Entry m = (Map.Entry) obj;
            Object value = m.getValue();
            Employee e = (Employee)value;

            if(e.getSal() > 18000){
                System.out.println(e);
            }
        }

    }
}
class Employee{
    private String name;
    private double sal;
    private int id;

    public Employee(String name, double sal, int id) {
        this.name = name;
        this.sal = sal;
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getSal() {
        return sal;
    }

    public void setSal(double sal) {
        this.sal = sal;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    @Override
    public String toString() {
        return "Employee{" +
                "name='" + name + '\'' +
                ", sal=" + sal +
                ", id=" + id +
                '}';
    }
}